<div class="opwindow">
	<form name="theform2" id="theform2" method="post" action="{echo \befen\get_url()}">
	<div class="layui-form layui-row">
		<div class="layui-form-item">
			<div class="layui-col layui-col-md4">
				<label>商户名称</label>
				<input type="text" name="merchant_name" id="merchant_name" class="layui-input layui-input-wdith" value="" placeholder="请输入商户名称">
			</div>
			<div class="layui-col layui-col-md4">
				<label>商户类型</label>
				<div class="layui-input-inline layui-input-wdith">
					<select name="merchant_type" id="merchant_type" class="layui-select" placeholder="请选择商户类型">
						<option value="">选择商户类型</option>
						<!--{loop model('Merchant')->get_type() $key $val}-->
						<option value="{$val}">{$val}</option>
						<!--{/loop}-->
					</select>
				</div>
			</div>
			<div class="layui-col layui-col-md4">
				<label>行业类型</label>
				<div class="layui-input-inline layui-input-wdith">
					<select name="merchant_industry" id="merchant_industry" class="layui-select" placeholder="请选择行业类型">
						<option value="">选择行业类型</option>
						<!--{loop model('Merchant')->get_industry() $key $val}-->
						<option value="{$val}">{$val}</option>
						<!--{/loop}-->
					</select>
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-col layui-col-md4">
				<label>负责人姓名</label>
				<input type="text" name="per_name" id="per_name" class="layui-input layui-input-wdith" value="" placeholder="请输入负责人姓名">
			</div>
			<div class="layui-col layui-col-md4">
				<label>负责人电话</label>
				<input type="text" name="per_phone" id="per_phone" class="layui-input layui-input-wdith" value="" placeholder="请输入负责人电话">
			</div>
			<div class="layui-col layui-col-md4">
				<label>负责人邮箱</label>
				<input type="text" name="per_email" id="per_email" class="layui-input layui-input-wdith" value="" placeholder="请输入负责人邮箱">
			</div>
		</div>
		<div class="layui-form-item" id="area-picker">
			<input type="hidden" id="area_code" name="area_code" value="">
			<div class="layui-col layui-col-md4">
				<label>所属省级</label>
				<div class="layui-input-inline layui-input-wdith">
					<select name="province" id="province" class="province-selector" data-value=""><option value="">--选择省--</option></select>
				</div>
			</div>
			<div class="layui-col layui-col-md4">
				<label>所属市级</label>
				<div class="layui-input-inline layui-input-wdith">
					<select name="city" id="city" class="city-selector" data-value=""><option value="">--选择市--</option></select>
				</div>
			</div>
			<div class="layui-col layui-col-md4">
				<label>所属区级</label>
				<div class="layui-input-inline layui-input-wdith">
					<select name="county" id="county" class="county-selector" data-value=""><option value="">--选择区--</option></select>
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-col layui-col-md4">
				<label>经营地址</label>
				<input type="text" name="address" id="address" class="layui-input layui-input-wdith" value="" placeholder="请输入经营地址">
			</div>
			<div class="layui-col layui-col-md4">
				<label>支付宝</label>
				<input type="text" name="alipay" id="alipay" class="layui-input layui-input-wdith" value="" placeholder="请输入支付宝账号">
			</div>
			<div class="layui-col layui-col-md4">
				<label>备注信息</label>
				<input type="text" name="remarks" id="remarks" class="layui-input layui-input-wdith" value="">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-col layui-col-md4">
				<label>商户信息-开户银行</label>
				<div style="position:relative;">
					<input type="text" name="account_bank" id="account_bank" class="layui-input layui-input-wdith" value="" placeholder="请输入开户银行">
				</div>
			</div>
			<div class="layui-col layui-col-md4">
				<label>商户信息-账户名称</label>
				<input type="text" name="account_name" id="account_name" class="layui-input layui-input-wdith" value="" placeholder="请输入账号名称">
			</div>
			<div class="layui-col layui-col-md4">
				<label>商户信息-账户卡号</label>
				<input type="text" name="account_number" id="account_number" class="layui-input layui-input-wdith" value="" placeholder="请输入银行卡号">
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-col layui-col-md2">
				<label>营业执照</label>
				<div class="mch-box">
					<img id="license_copy" class="mch-img" src="">
					<input type="hidden" name="license_copy" class="mch-obj" value="">
				</div>
			</div>
			<div class="layui-col layui-col-md2">
				<label>身份证人像面</label>
				<div class="mch-box">
					<img id="id_card_copy" class="mch-img" src="">
					<input type="hidden" name="id_card_copy" class="mch-obj" value="">
				</div>
			</div>
			<div class="layui-col layui-col-md2">
				<label>身份证国徽面</label>
				<div class="mch-box">
					<img id="id_card_national" class="mch-img" src="">
					<input type="hidden" name="id_card_national" class="mch-obj" value="">
				</div>
			</div>
			<div class="layui-col layui-col-md2">
				<label>商户门头照片</label>
				<div class="mch-box">
					<img id="store_door" class="mch-img" src="">
					<input type="hidden" name="store_door" class="mch-obj" value="">
				</div>
			</div>
			<div class="layui-col layui-col-md2">
				<label>店内环境照片</label>
				<div class="mch-box">
					<img id="store_inside" class="mch-img" src="">
					<input type="hidden" name="store_inside" class="mch-obj" value="">
				</div>
			</div>
			<div class="layui-col layui-col-md2">
				<label>特殊资质证明</label>
				<div class="mch-box">
					<img id="qualifications" class="mch-img" src="">
					<input type="hidden" name="qualifications" class="mch-obj" value="">
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-col layui-col-md12" style="text-align:right;">
				<button type="submit" name="submit2" value="submit2" id="submit2" class="layui-btn">提交</button>
			</div>
		</div>
	</div>
	</form>
</div>
<link rel="stylesheet" href="//at.alicdn.com/t/font_1614161_8o9u8s6h5fn.css" />
<style>
.layui-btn-download {width:96px;margin-top:5px;}
.mch-box { position:relative;width:96px;height:96px; }
.mch-box .mch-img { width:100%;height:100%;cursor:pointer; }
.mch-box .mch-view {
	position:absolute;
	top:0px;
	left:0px;
	width:100%;
	height:100%;
	background-color:rgba(0, 0, 0, .5);
	padding-top:35px;
	text-align:center;
	display:none;
	box-sizing:border-box;
	-moz-box-sizing:border-box;
	-webkit-box-sizing:border-box;
}
.mch-box .mch-view .iconfont {color:#FFF;font-size:24px;margin:0 3px;}
</style>
<script type="text/javascript">
var merchant_id = "{echo input('param.merchant_id')}";
init_Form();
init_Layarea("#area-picker", {
	change: res => { $('#area_code').val(res.countyCode) }
});
$(".mch-box").each(function(index){
	var mch_box = $(this);
	var mch_img = $(this).find(".mch-img");
	var mch_obj = $(this).find(".mch-obj");
	mch_box.hover(function(){
		if($(this).hasClass("hasImg")) {
			$(this).find(".mch-view").fadeIn(200);
		}
	}, function(){
		$(this).find(".mch-view").hide();
	});
	if(mch_obj.val()) {
		mch_box.addClass("hasImg");
		mch_img.attr("src", mch_obj.val());
	} else {
		mch_box.removeClass("hasImg");
		mch_img.attr("src", "/public/system/add-img.png");
	}
	add_upload(mch_img);
	mch_box.append('<p class="mch-view"><a href="javascript:;" class="iconfont icon-browse" title="预览"></a><a href="javascript:;" class="iconfont icon-ashbin" title="删除"></a></p>');
});
$(".icon-ashbin").click(function(){
	$(this).parent().hide();
	$(this).parent().parent().removeClass("hasImg");
	$(this).parent().parent().find(".mch-obj").val("");
	$(this).parent().parent().find(".mch-img").attr("src", "/public/system/add-img.png");
});
$(".icon-browse").click(function(){
	$(this).parent().hide();
	layer.photos({
		anim: 5,
		photos: {
			title: "",
			id: 0,
			start: 0,
			data: [
				{
					alt: "",
					pid: 0,
					src: $(this).parent().parent().find(".mch-obj").val(),
					thumb: $(this).parent().parent().find(".mch-obj").val(),
				}
			]
		}
	});
});
function add_upload(elem) {
	if(!elem) {
		elem = '.item-upload';
	}
	init_upload({
		elem: elem,
		url: "{echo url('merchant/upload', ['merchant_id' => input('param.merchant_id')])}",
		exts: "png|jpg",
		acceptMime: "image/*",
		callback: function(item, data, index, upload){
			//console.log(item);
			//console.log(data);
			if(data.status == 0) {
				showAlert(data.message);
			} else {
				item.parent().addClass("hasImg");
				item.attr("src", data.message);
				item.parent().find(".mch-obj").val(data.message);
			}
		}
	});
}
$('#theform2 input[name=account_bank]').autoComplete({
	url: "{echo url('banks/index')}",
	field: "",
	value: "",
	name_hidden: "bank_code",
	value_hidden: "",
});
$("#submit2").click(function(){
	if(false == checkMerchant("#theform2")) {
		return false;
	}
	var the_btn = "#submit2";
	var the_form = "#theform2";
	$(the_form).ajaxForm({
		dataType: "json",
		timeout: 30000,
		data: {ajax:"json"},
		success: function(data){
			if(data.status == "nologin") {
				showAlert(data.message, function(){
					reload();
				});
			} else if(data.status == 0) {
				showAlert(data.message);
			} else if(data.status == 1) {
				var msg = '';
				msg += '<div style="line-height:30px;color:#009688;font-size:18px;">';
				msg += '添加成功！';
				msg += '<br>';
				msg += '登录账号：' + data.contents.merchant_no;
				msg += '<br>';
				msg += '登录密码：' + data.contents.merchant_password;
				msg += '</div>';
				_Layer(function(){
					layer.close(index_window);
					layer.alert(msg, {
						anim:0,
						shade:0.5,
						isOutAnim:true,
						closeBtn:0,
					}, function(index){
						layer.close(index);
						reload();
					});
				});
			}
		},
		error: function(data){
			showAlert("提交数据失败");
		},
		complete: function(){
			submit(0, the_btn, the_form);
		},
		beforeSend: function(){
			submit(1, the_btn, the_form);
		}
	});
});
</script>
